#ifndef SEMANTIC_ANALYZER_H
#define SEMANTIC_ANALYZER_H

#include "compiler/parser.h"
#include "execution/catalog.h"
#include <memory>
#include <stdexcept>

class SemanticError : public std::runtime_error {
public:
    SemanticError(const std::string& msg, int line, int col)
        : std::runtime_error("[SEMANTIC_ERROR, " + std::to_string(line) + ", " + std::to_string(col) + "] " + msg) {}
};

class SemanticAnalyzer {
public:
    SemanticAnalyzer(std::shared_ptr<Catalog> catalog);

    void analyze(const std::unique_ptr<AST::Statement>& stmt);

private:
    void analyzeCreateTable(const AST::CreateTableStmt& stmt);
    void analyzeInsert(const AST::InsertStmt& stmt);
    void analyzeSelect(const AST::SelectStmt& stmt);
    void analyzeDelete(const AST::DeleteStmt& stmt);
    void analyzeExpression(const AST::Expression& expr, const TableInfo* tableInfo);

    std::shared_ptr<Catalog> catalog;
};

#endif // SEMANTIC_ANALYZER_H